package com.cfjjc.gz.common.action;

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.springframework.beans.factory.annotation.Autowired;
import com.cfjjc.gz.common.service.CommonService;
import com.cfjjc.gz.common.util.ImageCode;
 

/**
 * 
 * 通用Action类
 */

public class CommonAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4148907082852640890L;

	private Map model = new HashMap();

	/**
	 * 在这里只需要声明使用到的业务逻辑层对象,其实例由spring负责创建
	 */
	@Autowired
	private CommonService commonService;

	public Object getModel() {
		return model;
	}

	// 生成校验码
	public void makeValidateCode() throws Exception {

		response.setContentType("image/jpeg");
		ImageCode image = new ImageCode();
		response.setHeader("Expires", "Sat, 16 Jan 1980 12:00:00 GMT");
		response.setHeader("Cache-Control",
				"no-store, no-cache, must-revalidate");
		response.addHeader("Cache-Control", "post-check=0, pre-check=0");
		response.setHeader("Pragma", "no-cache");

		try {
			// 输出图象到页面
			BufferedImage img = image.creatImage();
			session.put("rand", image.getSRand());
			ImageIO.write(img, "JPEG", response.getOutputStream());
			response.getOutputStream().flush();
			response.getOutputStream().close();
		} catch (Exception e) {
			this.addActionError("抱歉,目前无法登录,请联系管理员！错误信息" + e.getMessage());
		}
	}

	@Override
	public List<?> getRows() {
		return null;
	}

	@Override
	public Integer getTotal() {
		return null;
	}
}
